package io.kimmking.rpcfx.metadata.center;

import io.kimmking.rpcfx.api.RpcfxProvider;
import io.kimmking.rpcfx.metadata.center.api.MethodInfo;
import io.kimmking.rpcfx.metadata.center.api.Server;

import java.lang.reflect.Method;

/**
 * @author lfy
 */
public class ParseServiceUtil {

    public static Server parse(  String serverClass) throws ClassNotFoundException {
        Class<?> clazz = Class.forName(serverClass);
        Server server = new Server();
        server.setServerName(serverClass);
        Method[] declareMethods = clazz.getDeclaredMethods();
        MethodInfo[]methodInfos = new MethodInfo[declareMethods.length];
        for (int i = 0; i < declareMethods.length; i++) {
            MethodInfo methodInfo = new MethodInfo();
            Method m = declareMethods[i];
            Class<?> returnType = m.getReturnType();
            Class<?>[] parameterTypes = m.getParameterTypes();
            methodInfo.setReturnType(returnType);
            methodInfo.setArgs(parameterTypes);
            methodInfo.setMethodName(m.getName());
            methodInfos[i] = methodInfo;
        }
        server.setMethods(methodInfos);
        return server;
    }


}
